//--------------------Sonic CD HUD Script---------------------//
//--------Scripted by Christian Whitehead 'The Taxman'--------//
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//

// Aliases
// Not all of these are used here in the HUD script, some are just used as a way for other objects to globally transmit values
private alias Object.Value0 : Object.Timer     // Initially set via a loop in the UFO script
private alias Object.Value1 : Object.GoldenFreddyTimer     // Initially set via a loop in the UFO script
private alias Object.Value3 : Object.GoldenFreddyRandom    // Initially set via a loop in the UFO script
private alias Object.Value4 : Object.GoldenFreddyAI    // Initially set via a loop in the UFO script
private alias Object.Value5 : Object.ScareTimer    // Initially set via a loop in the UFO script

private alias Object.Value6 : Object.GoldenFreddyRise    // Initially set via a loop in the UFO script
private alias Object.Value7 : Object.MoveTime    // Initially set via a loop in the UFO script
private alias Object.Value8 : Object.RandomLocation1    // Initially set via a loop in the UFO script

private alias Object.Value9 : Object.DoorTime    // Initially set via a loop in the UFO script
private alias Object.Value10 : Object.HeadShake    // Initially set via a loop in the UFO script
private alias Object.Value11 : Object.Tweak    // Initially set via a loop in the UFO script

private alias Object[2].Value2 : Object.ScrollPos

// Priority
private alias 1 : PRIORITY_ACTIVE

private alias 0 : CAM_SHOWSTAGE_0
private alias 1 : CAM_DININGHALL_1
private alias 2 : CAM_BACKSTAGE_2
private alias 3 : CAM_PIRATESCOVE_3
private alias 4 : CAM_WESTHALL_4
private alias 5 : CAM_CLOSET_5
private alias 6 : CAM_WHALLCORNER_6
private alias 7 : CAM_EASTHALL_7
private alias 8 : CAM_EHALLCORNER_8
private alias 9 : CAM_KITCHEN_9
private alias 10 : CAM_BATHROOMS_10

private alias 15 : OFFICE_ATDOOR
private alias 16 : OFFICE_JUMPSCARES

private alias object.state : GoldenFreddy.State

private alias 2  : CAMERA_MAIN
private alias 10  : CAMERA_EXIT



event ObjectMain
//-1 is basically the ai level 0 ig

if Object[5].Type == TypeName[Blank Object]



	switch GoldenFreddy.state
	case 15
		Object.ScareTimer++
		Object.DoorTime = 325
		rand(temp2, 50)
		Object.DoorTime += temp2
		if Object.ScareTimer >= Object.DoorTime
			if RightDoorClosed == 1
				if Object.ScareTimer >= 450
					Object.ScareTimer = 0	

						if Object[2].Value6 == 1
							StopSfx(SfxName[Hum])
							Object[2].Value6 = 0
							PowerUsage--
						end if

					GoldenFreddy.state = 1
				end if
			else
				RDoorLocked = 1
				object.state++
				Object.ScareTimer = 0
			end if
		end if		
	break
	case 16	//wa
		Object.ScareTimer++
		Object.DoorTime = 310
		rand(temp2, 100)
		Object.DoorTime += temp2
		if Object.ScareTimer >= Object.DoorTime
			StopMusic()
			PlaySfx(SfxName[Jumpscare], 0)			
			object.state++
		end if
	break	
	case 17
		PlayerJumpscared = 1
		if Object.GoldenFreddyRise > -100
			Object.GoldenFreddyRise -= 16
		else
			Object.GoldenFreddyRise = -100
		end if
	break	
	case 1
		Object.GoldenFreddyTimer++
		if MaskEquipped == 1
			object.alpha -= 16
		else	
			if object.alpha < 255
				object.alpha += 8
			end if
			if Object.GoldenFreddyTimer >= 200
				StopMusic()
				PlaySfx(SfxName[Jumpscare], 0)				
				object.state = 17
				Object.GoldenFreddyTimer = 0
			end if	
		end if

		if object.alpha <= 0
			Object.GoldenFreddyTimer = 0
			object.state = 0
		end if
	break	
	case 0
		Object.GoldenFreddyTimer++
		if Object.GoldenFreddyTimer == 100
			Rand(Object.GoldenFreddyRandom, 21)
			Object.GoldenFreddyTimer = 0
		end if	
		if object[6].state == CAMERA_EXIT
			if Object.GoldenFreddyAI > Object.GoldenFreddyRandom 
				PlaySfx(SfxName[GoldenFreddy], 0)	
				object.alpha = 255
				Object.GoldenFreddyTimer = 0
				GoldenFreddy.State = 1
			end if
		end if
	break
	end switch
end if	
end event

event ObjectDraw

//	DrawNumbers(0, 32, 96, Object.GoldenFreddyRandom, 3, 8, 0)

//	DrawNumbers(0, 64, 96, GoldenFreddy.State, 3, 8, 0)

//	DrawNumbers(0, 96, 96, Object.DoorTime, 3, 8, 0)

	
	rand(Object.HeadShake, 8)

	if GoldenFreddy.state == 17
		object.drawOrder = 5
		temp1 = Screen.xsize
		temp1 /= 2
		temp1 -= 140
		
		temp2 = temp1
		temp2 += Object.HeadShake

		DrawSpriteScreenFX(10, FX_SCALE, temp2, Object.GoldenFreddyRise)	//body
		DrawSpriteScreenFX(11, FX_SCALE, temp2, Object.GoldenFreddyRise)	//head
	end if

	object.inkeffect = 2
	switch GoldenFreddy.state
	case 1
	case 2
		DrawSpriteScreenFX(12, FX_INK, Object.ScrollPos, 40)
		DrawSpriteScreenFX(12, FX_INK, Object.ScrollPos, 40)
	break
	end switch	

end event


event ObjectStartup
	
	LoadSpriteSheet("FNAF/Jumpscares.gif")
	
	// Place the HUD object into reserved object slot 4 and initialise its values
	Object[15].Type = TypeName[GoldenFreddy]
	
	// The object should always be run, regardless if it's within camera bounds or not
	Object[15].Priority = PRIORITY_ACTIVE
	
	// Make the HUD draw ontop of all other sprites, too
	Object[15].DrawOrder = 4

	// 0-9 - Numbers 0-9
	SpriteFrame(0, 0, 8, 13, 558, 1)
	SpriteFrame(0, 0, 8, 13, 567, 1)
	SpriteFrame(0, 0, 8, 13, 576, 1)
	SpriteFrame(0, 0, 8, 13, 585, 1)
	SpriteFrame(0, 0, 8, 13, 594, 1)
	SpriteFrame(0, 0, 8, 13, 558, 15)
	SpriteFrame(0, 0, 8, 13, 567, 15)
	SpriteFrame(0, 0, 8, 13, 576, 15)
	SpriteFrame(0, 0, 8, 13, 585, 15)
	SpriteFrame(0, 0, 8, 13, 594, 15)

	SpriteFrame(0, 280, 298, 83, 1, 940)
	SpriteFrame(46, 100, 206, 227, 1, 712)	//11

	SpriteFrame(140, 41, 166, 169, 1, 193)	//12

end event


// ========================
// Editor events
// ========================

event RSDKDraw
	DrawSprite(0)
end event


event RSDKLoad
	LoadSpriteSheet("3D_Test/Objects.gif")
	SpriteFrame(0, 0, 24, 16, 206, 58)

	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
